package net.hserver.apm.service;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;
import net.hserver.apm.config.MongodbConfig;
import org.bson.BsonDocument;
import org.bson.BsonString;
import org.bson.Document;
import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.core.ioc.annotation.Bean;

import java.util.ArrayList;
import java.util.List;

@Bean
public class HomeService {

    @Autowired
    private MongoClient mongoClient;

    /***
     * 获取表想详细占用信息
     * @return
     */
    public Object getStats() {
        MongoDatabase database = mongoClient.getDatabase(MongodbConfig.DATA_BASE);
        List<Document> data = new ArrayList<>();
        data.add(database.runCommand(new BsonDocument("collStats", new BsonString("linkInfo"))));
        data.add(database.runCommand(new BsonDocument("collStats", new BsonString("logInfo"))));
        data.add(database.runCommand(new BsonDocument("collStats", new BsonString("requestInfo"))));
        data.add(database.runCommand(new BsonDocument("collStats", new BsonString("serverInfo"))));
        data.add(database.runCommand(new BsonDocument("collStats", new BsonString("sqlInfo"))));
        return data;
    }

}
